package com.biqee.action.admin;

import java.util.List;

import com.biqee.action.base.BaseAction;
import com.biqee.model.TbQueryModel;
import com.biqee.model.common.PageInfoObject;
import com.biqee.model.db.BqQuery;
import com.biqee.model.page.ItemVO;
import com.biqee.service.bq.BqDictService;
import com.biqee.service.bq.BqQueryRelationService;
import com.biqee.service.bq.BqQueryService;
import com.biqee.service.bq.EstimateService;

public class QueryManager extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = -271061134288684156L;
	private BqQueryService bqQueryService ;
	private BqQueryRelationService  bqQueryRelationService ;
	
	private PageInfoObject page = new PageInfoObject();
	private BqQuery bqQuery = new BqQuery();
	private Integer bqQueryRelationId ;
	private EstimateService estimateService;
	
	private List<ItemVO> itemsList;
	private BqDictService bqDictService;
	
	public String read(){
		Integer id= bqQuery.getId();
		if(id==null){
			return INPUT;
		}
	    bqQuery = bqQueryService.getById(id);
	    page.addParam("queryId", id);
	    itemsList = bqQueryRelationService.listRelationItemsByPage(page);
		return "manager";
	}
	
	public String search(){
		if(bqQuery.getId()==null){
			return INPUT;
		}
		TbQueryModel tbQueryModel = new TbQueryModel();
		bqQuery.setType(BqQuery.TYPE_MANUAL);
		tbQueryModel.setBqQuery(bqQuery);
		bqQueryService.searchTbItems(tbQueryModel);
		estimateService.reEstimate(bqQuery.getTuanId());
		bqDictService.addWords(bqQuery.getQueryQ());
		return read();
	}
	
	public void setEstimateService(EstimateService estimateService) {
		this.estimateService = estimateService;
	}

	public String deleteReletion(){
		
		if(bqQueryRelationId!=null){
			bqQueryRelationService.delete(bqQueryRelationId);
		}
		return "read";
	}
	
	public String delete(){
		if(bqQuery.getId()!=null){
			 bqQueryService.delete(bqQuery.getId());
			 return INPUT;
		}else{
			return "read";
		}
		
	}

	
	public String manager(){
		
		return "manager";
	}


	public void setBqQueryService(BqQueryService bqQueryService) {
		this.bqQueryService = bqQueryService;
	}


	
	public PageInfoObject getPage() {
		return page;
	}

	public void setPage(PageInfoObject page) {
		this.page = page;
	}

	public Object getModel() {
		return bqQuery;
	}

	public BqQuery getBqQuery() {
		return bqQuery;
	}

	public void setBqQuery(BqQuery bqQuery) {
		this.bqQuery = bqQuery;
	}

	public void setBqQueryRelationService(
			BqQueryRelationService bqQueryRelationService) {
		this.bqQueryRelationService = bqQueryRelationService;
	}

	public List<ItemVO> getItemsList() {
		return itemsList;
	}

	public void setItemsList(List<ItemVO> itemsList) {
		this.itemsList = itemsList;
	}

	public Integer getBqQueryRelationId() {
		return bqQueryRelationId;
	}

	public void setBqQueryRelationId(Integer bqQueryRelationId) {
		this.bqQueryRelationId = bqQueryRelationId;
	}

	public void setBqDictService(BqDictService bqDictService) {
		this.bqDictService = bqDictService;
	}

	


	

}
